package com.qcby.mycommunity_003.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qcby.mycommunity_003.entity.Role;
import com.qcby.mycommunity_003.mapper.RoleMapper;
import com.qcby.mycommunity_003.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcby.mycommunity_003.vo.PageVo;
import com.qcby.mycommunity_003.vo.RoleListVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-03-24
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private RoleService roleService;
    @Override
    public String getRoleNameByUserId(Integer id) {
        return roleMapper.getRoleNameByUserId(id);
    }

    @Override
    public PageVo Rolelist(RoleListVo listVo) {
        Page<Role> page=new Page<>();
        page.setSize(listVo.getLimit());
        page.setCurrent(listVo.getPage());
        QueryWrapper<Role> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(listVo.getRoleName()),"role_name",listVo.getRoleName());
        Page<Role> page1 = roleMapper.selectPage(page, queryWrapper);
        List<Role> list=new ArrayList<>();
        for (Role role : page1.getRecords()) {
            list.add(role);
        }
        PageVo Vo=new PageVo();
        Vo.setList(list);
        Vo.setTotalPage(page1.getPages());
        Vo.setTotalCount(page1.getTotal());
        Vo.setCurrPage(page1.getCurrent());
        Vo.setPageSize(page1.getSize());
        return Vo;
    }
}
